package com.ruoyi.project.remake.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.remake.domain.TCaseMain;
import com.ruoyi.project.remake.service.ITCaseMainService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 病例主表Controller
 * 
 * @author 孙山伟
 * @date 2020-12-14
 */
@RestController
@RequestMapping("/remake/caseMain")
public class TCaseMainController extends BaseController
{
    @Autowired
    private ITCaseMainService tCaseMainService;

    /**
     * 查询病例主表列表
     */
    @PreAuthorize("@ss.hasPermi('remake:caseMain:list')")
    @GetMapping("/list")
    public TableDataInfo list(TCaseMain tCaseMain)
    {
        startPage();
        List<TCaseMain> list = tCaseMainService.selectTCaseMainList(tCaseMain);
        return getDataTable(list);
    }

    /**
     * 导出病例主表列表
     */
    @PreAuthorize("@ss.hasPermi('remake:caseMain:export')")
    @Log(title = "病例主表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TCaseMain tCaseMain)
    {
        List<TCaseMain> list = tCaseMainService.selectTCaseMainList(tCaseMain);
        ExcelUtil<TCaseMain> util = new ExcelUtil<TCaseMain>(TCaseMain.class);
        return util.exportExcel(list, "caseMain");
    }

    /**
     * 获取病例主表详细信息
     */
    @PreAuthorize("@ss.hasPermi('remake:caseMain:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tCaseMainService.selectTCaseMainById(id));
    }

    /**
     * 新增病例主表
     */
    @PreAuthorize("@ss.hasPermi('remake:caseMain:add')")
    @Log(title = "病例主表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCaseMain tCaseMain)
    {
        return toAjax(tCaseMainService.insertTCaseMain(tCaseMain));
    }

    /**
     * 修改病例主表
     */
    @PreAuthorize("@ss.hasPermi('remake:caseMain:edit')")
    @Log(title = "病例主表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCaseMain tCaseMain)
    {
        return toAjax(tCaseMainService.updateTCaseMain(tCaseMain));
    }

    /**
     * 删除病例主表
     */
    @PreAuthorize("@ss.hasPermi('remake:caseMain:remove')")
    @Log(title = "病例主表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tCaseMainService.deleteTCaseMainByIds(ids));
    }
}
